<!-- 我的搜索 -->

<template>
  <div class="MapPoint-MySearch">
    <div class="MapPoint-MySearch-title">点位资源</div>

    <EasyScroll class="MapPoint-MySearch-list">
      <div v-for="item in iotTypeDict" :key="item[0]" @click.stop="toClick(item)">
        <CommonSvg class="inFlexCC" :src="CORE.common(`iot/${item[0]}.svg`)" @click="toClick(item)" />
        <div>{{ item[1] }}</div>
      </div>
    </EasyScroll>
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MySearch',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [
    CORE.mixWeb('map', 'map_'),
    CORE.mixInfo('map', 'map_'),
    CORE.mixSelect('map', 'map_'),
    CORE.mixSelect('firefighting', 'firefighting_'),
    CORE.mixSelect(),
  ],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 设备类型字典 (deviceCategoryId, deviceCategoryName, subSystemId, 菜单路由)
     */
    iotTypeDict() {
      return this.DICT.IOT_TYPE.filter(([, , , routeList]) => {
        for (const route of routeList) {
          // 地图页
          if (CORE.MENU.ROUTE[route]) return true // 路由直接存在
          if (CORE.MENU.ROUTE[CORE.ROUTE.NAME_TRANS[route]]) return true // 路由转换存在

          // 管理页
          const manage = route.replace(/Map$/, 'Manage')
          if (CORE.MENU.ROUTE[manage]) return true // 路由直接存在
          if (CORE.MENU.ROUTE[CORE.ROUTE.NAME_TRANS[manage]]) return true // 路由转换存在
        }

        return false
      })
    },
  },

  /**
   * 挂载完成 (先抽取再调用)
   */
  mounted() {
    if (this.iotTypeDict.some((item) => item[0] === '24')) {
      CORE.merge(this.firefighting_selectParam, {
        hasFirefighting: true, // 是否有消防点位
        pointTypeCode: '', // 点位类型编号
      })
      this.firefighting_startSelect()
    }
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 点击子系统
     */
    toClick([id]) {
      this.map_param.deviceCategoryId = id
      this.map_setList()
      this.map_startList()

      this.map_selectParam.deviceCategoryId = id === 'line' ? '1' : ''
      this.map_setSelect()
      this.map_startSelect()

      this.selectParam.deviceCategoryId = id === 'line' ? '1' : id
      this.selectParam.nextIdList = [this.map_infoParam.areaId]
      this.setSelect()
      this.startSelect()
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
